const Actions = require('./actions');
const DB = require('../../app/db');
import { Storage } from 'clientConfig/util/StoreData'
import { Toast } from 'saltui';
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {

    },

    onFetchEvaluteList: function (pageNum, props, success, error) {
        let t = this;
        DB.Parent.get_Evalute_lists({
            schoolId: Storage.get('user.schoolId'),
            studentId: Storage.get('user.studentId'),
            pageIndex: pageNum,
        })
            .then((content) => {
                let schoolId = content.check.schoolId;
                let studentId = content.check.studentId;
                content = content.data.EvaluateList;
                var list = [];
                var obj = {};
                if (content && content.length > 0) {
                    for (let item of content) {
                        obj["schoolId"] = schoolId;
                        obj["badge"] = false;
                        obj["title"] = item.evaluateRank;
                        obj["subtitle"] = item.createDate;
                        obj["content"] = item.remark;
                        obj["evaluateId"] = item.evaluateId;
                        list.push(obj);
                        obj = {};
                    }
                }
                const hasNoMore = list.length < props.pageSize;
                t.data.listData = list;
                if (success) {
                    success(hasNoMore, list);
                } else if (!content || !success) {
                    error();
                }
            })
            .catch(function (error) {
                Toast.show({
                    type: 'error',
                    content: '系统异常'
                });
            });
    },
    updateComponent: function () {
        this.trigger(this.data);
    }
});
